package com.twu.biblioteca;

import com.twu.biblioteca.options.*;

import java.util.Map;
import java.util.TreeMap;

public class Options {
    private TreeMap<String, Option> optionTreeMap = new TreeMap<String, Option>();

    public Options() {
        optionTreeMap.put("1", new ViewAllBooks());
        optionTreeMap.put("2", new ReserveBook());
        optionTreeMap.put("3", new CheckMembershipDetails());
        optionTreeMap.put("4", new ViewAllMovies());
        optionTreeMap.put("5", new ExitSystem());
    }

    public void setOptionTreeMap(TreeMap<String, Option> optionTreeMap) {
        this.optionTreeMap = optionTreeMap;
    }

    public Option getOptionFromOptionNumber(String optionNumber) {
        Option option = optionTreeMap.get(optionNumber);
        if (option == null) {
            option = new InvalidOption();
        }
        return option;
    }

    @Override
    public String toString() {
        StringBuffer optionMenu = new StringBuffer();
        for (Map.Entry<String, Option> optionEntry : optionTreeMap.entrySet()) {
            optionMenu.append(optionEntry.getKey() + ". " + optionEntry.getValue().toString() + "\n");
        }
        return optionMenu.toString();
    }
}
